﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Cloud.Model;
using Cloud.BLL;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class Three_Managerment_Problem_save_Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
// 13841039277
//15898012458
{

        if (!IsPostBack)
        {  
            string sql7 = " insert into Problem values(1,ISNULL((( select CONVERT (bigint, (SELECT top(1) appealid FROM problem WHERE regtime >(select cast(convert(varchar(10),getdate(),120)+' 00:00:00' as datetime) )order by id desc) )+1)),(convert(varchar(10),getdate(),112 )+'00001')),GETDATE(),'1900-01-01 00:00:00','1900-01-01 00:00:00', 0,'','','',0,0,0,0,0,0,0,0,0,0,0 ,'','','','','' ,'','','',0,0,0,0,0 ,0,0)select @@identity as num ";
            String bh = ProblemManager.FindById(Convert.ToInt32(ProblemManager.pcount(sql7))).Appealid ;
          
          


            biaohao.Value =  bh;
       

            this.guishu.DataSource = AscriptionManager.FindAll();
            this.guishu.DataTextField = "name";
            this.guishu.DataValueField = "id";
            this.guishu.DataBind();

            this.feilei.DataSource = Classification_Appeal1Manager.FindAll();
            this.feilei.DataTextField = "name";
            this.feilei.DataValueField = "id";
            this.feilei.DataBind();

            this.xiaolei.DataSource = Classification_Appeal2Manager.FindBySort(Convert.ToInt32(this.feilei.SelectedItem.Value));
            this.xiaolei.DataTextField = "name";
            this.xiaolei.DataValueField = "id";
            this.xiaolei.DataBind();

            this.num.Value = Request.QueryString["gh"].ToString();
            this.tel.Value = Request.QueryString["tel"].ToString();
            bind();
            this.doing.Style.Add("display", "block");
            this.divLogin.Style.Add("display", "block");



        }
    }
    protected void Unnamed_Click(object sender, EventArgs e)
    {

        Problem activity = ProblemManager.findappid(this.biaohao.Value);

        if (rad.Checked)
        {
            activity.Opens = 1;
        }
        else
        {
            activity.Opens = 0;
        }

        if (rad3.Checked)
        {
            activity.Important = 1;
        }
        else
        {
            activity.Important = 0;
        }

        if (rad5.Checked)
        {
            activity.Emergencys = 1;
        }
        else
        {
            activity.Emergencys = 0;
        }

        if (rad7.Checked)
        {
            activity.Repeats = 1;
        }
        else
        {
            activity.Repeats = 0;
        }
        if (rad9.Checked)
        {
            activity.Secrecy = "0";
        }
        else
        {
            activity.Secrecy = "1";
        }

        activity.Appeal_name = this.name.Value;
        activity.Appeal_email = this.email.Value;
        activity.Appeal_tel = this.tel.Value;
        activity.Appeal_type_id = Convert.ToInt32(this.feilei.SelectedItem.Value);
        activity.Appealid = this.biaohao.Value;
        activity.Ascription_id = Convert.ToInt32(this.guishu.SelectedItem.Value);
        activity.Bldwid = "";
        activity.Bm1_type = 9;
        activity.Bm2_type = 9;
        activity.Context = con.Value;
        activity.Current_ld = 0;
        activity.Db_num = 0;
        activity.Handle_type = 0;
        activity.Ischeck = 1;
        activity.Jobnum = Convert.ToInt32(this.num.Value);
        activity.Mp3url = Request.QueryString["bh"];
        activity.Regtime = DateTime.Now;
        activity.Reject_num = 0;
        activity.Satisfied = 9;
        activity.Source_id = 1;
        activity.Title = this.title.Value;
        activity.Xbtime = new DateTime(1900, 01, 01, 00, 00, 00);
        activity.Xialei = Convert.ToInt32(this.xiaolei.SelectedItem.Value);
        activity.Zbtime = new DateTime(1900, 01, 01, 00, 00, 00);
        activity.Zrdwid = "";

        activity.Fankuiid = "";
        activity.Banjieid = "";   
        activity.Islook0 = 0;
        activity.Islook1 = 0;
        activity.Islook2 = 0;
        activity.Secrecy= "0";

        if (ProblemManager.Update(activity) > 0)
        {

            Problem_historic2 his = new Problem_historic2();
        
            his.Title = "录入 ";
            his.Bm2 = "";
            his.Evente = 0;
            his.Idopen = this.biaohao.Value;
            his.Blyj = this.nbyj.Value;

            his.Bm1 = "041";
            his.Item1 = 0;
            his.Item2 = "";
            his.Item3 = "";
            his.Name = "呼叫中心";
            his.Times = DateTime.Now;
            his.Timese = new DateTime(1900, 01, 01, 00, 00, 00);


            Problem_historic2Manager.Save(his);

            Response.Write("<script>alert('上报成功');location.href='tijiao.html'</script>");
        }
        else
        {
            Response.Write("<script>alert('上报失败');</script>");
        }

    }

    protected void Unnamed1_Click(object sender, EventArgs e)
    {

        Problem activity = ProblemManager.findappid(this.biaohao.Value);

        #region 单选

        if (rad.Checked)
        {
            activity.Opens = 1;
        }
        else
        {
            activity.Opens = 0;
        }

        if (rad3.Checked)
        {
            activity.Important = 1;
        }
        else
        {
            activity.Important = 0;
        }

        if (rad5.Checked)
        {
            activity.Emergencys = 1;
        }
        else
        {
            activity.Emergencys = 0;
        }

        if (rad7.Checked)
        {
            activity.Repeats = 1;
        }
        else
        {
            activity.Repeats = 0;
        }
        if (rad9.Checked)
        {
            activity.Secrecy = "0";
        }
        else
        {
            activity.Secrecy = "1";
        }

        #endregion

        activity.Appeal_name = this.name.Value;
        activity.Appeal_email = this.email.Value;
        activity.Appeal_tel = this.tel.Value;
        activity.Appeal_type_id = Convert.ToInt32(this.feilei.SelectedItem.Value);
        activity.Appealid = this.biaohao.Value;
        activity.Ascription_id = Convert.ToInt32(this.guishu.SelectedItem.Value);
        activity.Bldwid = "";
        activity.Bm1_type = 9;
        activity.Bm2_type = 9;
        activity.Context = con.Value;
        activity.Current_ld = 0;
        activity.Db_num = 0;
        activity.Handle_type = 4;
        activity.Ischeck = 1;
        activity.Jobnum = Convert.ToInt32(this.num.Value);
        activity.Mp3url = Request.QueryString["bh"];
        activity.Regtime = DateTime.Now;
        activity.Reject_num = 0;
        activity.Satisfied = 9;
        activity.Source_id = 1;
        activity.Title = this.title.Value;
        activity.Xbtime = new DateTime(1900, 01, 01, 00, 00, 00);
        activity.Xialei = Convert.ToInt32(this.xiaolei.SelectedItem.Value);
        activity.Zbtime = new DateTime(1900, 01, 01, 00, 00, 00);
        activity.Zrdwid = "";
        activity.Islook0 = 0;
        activity.Islook1 = 0;
        activity.Islook2 = 0;
        activity.Secrecy = "0";
        activity.Fankuiid = "";
        activity.Banjieid = "";

        if (ProblemManager.Update(activity) > 0)
        {

            Problem_historic2 his = new Problem_historic2();
      
            his.Title = "录入，直办 ";
            his.Bm2 = "";
            his.Evente = 8;
            his.Idopen = this.biaohao.Value;
            his.Blyj = this.nbyj.Value;

            his.Bm1 = "041";
            his.Item1 = 0;
            his.Item2 = "";
            his.Item3 = "";
            his.Name = "呼叫中心";
            his.Times = DateTime.Now;
            his.Timese = new DateTime(1900, 01, 01, 00, 00, 00);


            Problem_historic2Manager.Save(his);

            Response.Write("<script>alert('上报成功');location.href='tijiao.html'</script>");
        }
        else
        {
            Response.Write("<script>alert('上报失败');</script>");
        }

    }

    protected void Unnamed2_Click(object sender, EventArgs e)//无效电话
    {

        Problem activity = ProblemManager.findappid(this.biaohao.Value);

        if (rad.Checked)
        {
            activity.Opens = 1;
        }
        else
        {
            activity.Opens = 0;
        }

        if (rad3.Checked)
        {
            activity.Important = 1;
        }
        else
        {
            activity.Important = 0;
        }

        if (rad5.Checked)
        {
            activity.Emergencys = 1;
        }
        else
        {
            activity.Emergencys = 0;
        }

        if (rad7.Checked)
        {
            activity.Repeats = 1;
        }
        else
        {
            activity.Repeats = 0;
        }
        if (rad9.Checked)
        {
            activity.Secrecy = "0";
        }
        else
        {
            activity.Secrecy = "1";
        }

        activity.Appeal_name = this.name.Value;
        activity.Appeal_email = this.email.Value;
        activity.Appeal_tel = this.tel.Value;
        activity.Appeal_type_id = Convert.ToInt32(this.feilei.SelectedItem.Value);
        activity.Appealid = this.biaohao.Value;
        activity.Ascription_id = Convert.ToInt32(this.guishu.SelectedItem.Value);
        activity.Bldwid = "";
        activity.Bm1_type = 9;
        activity.Bm2_type = 9;
        activity.Context = "无效电话";
        activity.Current_ld = 0;
        activity.Db_num = 0;
        activity.Handle_type = 4;
        activity.Ischeck = 1;
        activity.Jobnum = Convert.ToInt32(this.num.Value);
        activity.Mp3url = Request.QueryString["bh"];
        activity.Regtime = DateTime.Now;
        activity.Reject_num = 0;
        activity.Satisfied = 9;
        activity.Source_id = 1;
        activity.Title = "无效电话";
        activity.Xbtime = new DateTime(1900, 01, 01, 00, 00, 00);
        activity.Xialei = Convert.ToInt32(this.xiaolei.SelectedItem.Value);
        activity.Zbtime = new DateTime(1900, 01, 01, 00, 00, 00);
        activity.Zrdwid = "";
        activity.Islook0 = 0;
        activity.Islook1 = 0;
        activity.Islook2 = 0;
        activity.Secrecy = "0";
activity.Fankuiid = "";
            activity.Banjieid = "";

        if (ProblemManager.Update(activity) > 0)
        {

            Problem_historic2 his = new Problem_historic2();
            his.Blyj = this.nbyj.Value;
            his.Title = "录入，无效电话 ";
            his.Bm2 = "";
            his.Evente = 8;
            his.Idopen = this.biaohao.Value;

            his.Bm1 = "041";
            his.Item1 = 0;
            his.Item2 = "";
            his.Item3 = "";
            his.Name = "呼叫中心";
            his.Times = DateTime.Now;
            his.Timese = new DateTime(1900, 01, 01, 00, 00, 00);


            Problem_historic2Manager.Save(his);

            Response.Write("<script>alert('上报成功');location.href='tijiao.html'</script>");
        }
        else
        {
            Response.Write("<script>alert('上报失败');</script>");
        }

    }
    protected void feilei_SelectedIndexChanged(object sender, EventArgs e)
    {

        this.xiaolei.DataSource = Classification_Appeal2Manager.FindBySort(Convert.ToInt32(this.feilei.SelectedItem.Value));
        this.xiaolei.DataTextField = "name";
        this.xiaolei.DataValueField = "id";
        this.xiaolei.DataBind();


    }


    //事件状态
    public string sjzt(int i)
    {
        try
        {

            String zts = "";
            if (i == 0)
            {
                zts = "待办理";
            }
            else if (i == 1)
            {
                zts = "已查看";
            }
            else if (i == 2)
            {
                zts = "已办理";
            }
            else if (i == 3)
            {
                zts = "已办结";
            }
            else if (i == 4)
            {
                zts = "直办";
            }
            return zts;
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            return "";
        }

    }


    public void bind()
    {
        try
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from problem where appeal_tel='" + Request.QueryString["tel"].ToString() + "' and regtime > '" + DateTime.Now.AddDays(-5).ToString("yyyy-MM-dd") + "' order by id desc", connection);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds, "problem");//固定不变的 
            repeater1.DataSource = ds.Tables["problem"];
            repeater1.DataBind();

            if (ds.Tables["problem"].Rows.Count > 0)
            {
                this.name.Value = ds.Tables["problem"].Rows[0]["appeal_name"].ToString();
            }

        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('登录超时'); window.parent.location.href='/index.html'</script>");
            return;
        }
    }
}